<template>
  <div
    class="remote"
    :class="device == 'mobile' ? 'mobile-container' : 'pc-container'"
  >
    <div style="margin-top: 8px" class="remote-box">
      <el-table
        ref="filterTable"
        height="250"
        row-class-name="custom-table-background"
        :data="tableData"
      >
        <el-table-column label="工厂名称">IKD</el-table-column>
        <el-table-column
          prop="edgeTime"
          width="160"
          label="报警时间"
        ></el-table-column>
        <el-table-column prop="content" fixed="right" label="报警信息">
        </el-table-column>
      </el-table>
      <div style="text-align: right">
        <el-pagination
          v-show="total > 0"
          background
          layout="total, pager, next"
          :total="total"
          :small="device == 'mobile'"
          style="margin-top: 10px"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[1, 2, 5, 10]"
          :page-size="pageSize"
          :current-page="currentPage"
          @prev-click="handleCurrentChange"
          @next-click="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { alarmRecord } from "@/api/home/main";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      tableData: [], //表格源数据
      tempData: [], //表格显示数据
      currentPage: 1, //当前页
      total: 0, //数据总数
      pageSize: 10, //一页展示的条数  默认一页展示10条，有很多数据就可以写其他的数
    };
  },
  computed: {
    ...mapGetters(["sidebar", "avatar", "device"]),
  },
  async mounted() {
    // this.handleCurrentChange(1);
    this.getDataList();
  },
  methods: {
    //每页条数切换
    handleSizeChange(val) {
      this.pageSize = val;
      this.handleCurrentChange(1);
    },
    //页码切换
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getDataList();
    },
    // 获取数据
    async getDataList() {
      let result = await alarmRecord({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
      let { total, records } = result;
      this.tableData = records;
      this.total = total;
    },
    //分页方法
    currentChangePage(list, currentPage) {
      let from = (currentPage - 1) * this.pageSize;
      let to = currentPage * this.pageSize;
      this.tempData = []; //每次要置空
      for (; from < to; from++) {
        if (list[from] != null) {
          //只有当list的内容不为空的时候才插入，不然会显示空行
          this.tempData.push(list[from]);
        }
      }
    },
    searchput() {
      this.tempData = []; //每次要置空
      this.tempData = this.tableData.filter((item, index) => {
        return item.name.includes(this.inputContent);
      });
    },
  },
};
</script>

<style scoped lang="scss">
.mr-10 {
  margin-right: 4px;
}
.mr-16 {
  margin-right: 10px;
}
.btn-list {
  float: left;
  margin-bottom: 16px;
}
.mobile-container {
  ::v-deep .el-dialog {
    width: 95% !important;
    margin-top: 20% !important;
  }
  ::v-deep .el-table--scrollable-y .el-table__body-wrapper {
    height: 300px !important;
  }
}
.remote {
  height: 100%;
  overflow: hidden;
}
.remote-box {
  height: calc(100% - 10px);
  width: 100%;
  display: flex;
  flex-direction: column;
}
</style>
